package com.p2p.front.dal.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;

import com.p2p.base.dao.BaseMapper;
import com.p2p.base.page.PageVo;
import com.p2p.front.dal.model.PwdProtectQuestion;

public interface ProtectQuestionDao extends BaseMapper{
	@Select("select * from p2p_protect_question where id =#{id}")
	PwdProtectQuestion findById(Long id);
	
	@Update("update p2p_protect_question set question = #{question},answer=#{answer},"
			+ "question_value=#{questionValue} where id=#{id}")
	void update(PwdProtectQuestion protectQuestion);
	
	@Insert("INSERT INTO p2p_protect_question(user_id,question,answer,question_value)values(#{userId},#{question},#{answer},#{questionValue})")
	void save(PwdProtectQuestion protectQuestion);
	
	@Select("select * from p2p_protect_question where user_id =#{id}")
	@Results(value = { @Result(property = "questionValue", 
	column = "question_value", javaType = String.class, jdbcType = JdbcType.VARCHAR)}) 
	PwdProtectQuestion findByUserId(String id);

	@Update("update p2p_protect_question set status=1 where id=#{id}")
	void remove(Integer id);

	@Select("select * from p2p_protect_question where status = 0")
	List<Map<String, Object>> list(PageVo form);

}
